package demo1;

import java.util.Arrays;

public class LeetCode1089 {
    public void duplicateZeros(int[] arr) {
        int left = -1, right = 0;
        int n = arr.length;
        while(right < n) {
            left++; right++;
            if(arr[left] == 0) right++;
        }
        int tmp = n - 1;
        if(right == n + 1) {
            arr[tmp--] = 0;
            left--;
        }
        while(tmp >= 0) {
            arr[tmp--] = arr[left];
            if(arr[left] == 0) arr[tmp--] = arr[left];
            left--;
        }
        System.out.println(Arrays.toString(arr));
    }
}
